<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2023/5/12
 * Time: 10:14
 */

namespace App\Rep;


use App\Models\BalanceHistory;

class BalanceHistoryRep
{
    /**
     * 添加扣款/充值记录
     * @param $customer_id
     * @param $amount
     * @param $befor
     * @param $after
     * @param $order_id
     * @param $business
     * @param string $detail
     */
    public function addBalanceHistoryRep($customer_id,$amount,$befor,$after,$order_id,$business,$detail=''){
        $history = new BalanceHistory();
        $history->date = date('Y-m-d H:i:s');
        $history->customer_id = $customer_id;
        $history->amount = $amount;
        $history->befor = $befor;
        $history->after = $after;
        $history->business = $business;
        $history->business_id = $order_id;
        $history->detail = $detail;
        $history->save();
    }

    /**
     * 获取流水账列表
     */
    public function getBalanceHistoryListRep($params){
        $list = BalanceHistory::Search($params)
            ->with(['customer'=>function($q){
                $q->select('id','customer_name');
            }])
            ->orderBy('id','desc')
            ->paginate($params['per_page']??10);
        return $list;
    }

}